(function () {
    "use strict";

    angular.module('core').factory('classificacaoTributariaIBSCBSService', factory);
    factory.$inject = ['$http', '$q'];

    function factory($http, $q) {

        var _get = function (id) {
            var deferred = $q.defer();
            $http.post('/ClassificacaoTributariaIBSCBS/get', id)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _getAll = function (args) {
            var deferred = $q.defer();
            $http.post('/ClassificacaoTributariaIBSCBS/getall', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _count = function (args) {
            var deferred = $q.defer();
            $http.post('/ClassificacaoTributariaIBSCBS/count', args)
                .success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };
        var _uploadCSV = function (file) {
            var deferred = $q.defer();
            var formData = new FormData();
            formData.append("file", file);

            $http.post("/ClassificacaoTributariaIBSCBS/ImportarCSV", formData, {
                transformRequest: angular.identity,
                headers: { "Content-Type": undefined }
            }).success(function (data) { deferred.resolve(data); })
                .error(function (data, status, headers, config) { deferred.reject(data); });
            return deferred.promise;
        };

        return {
            get: _get,
            getAll: _getAll,
            count: _count,
            uploadCSV: _uploadCSV
        };
    }

})();


